import React, { Component } from 'react'

export default class Form extends Component {
  state = {
    value: ''
  }

  handleChange = () => {
    return (e) => {
      this.setState({
        value: e.target.value
      })
    }
  }

  handleKeyUp = () => {
    return (e) => {
      // console.log(typeof e.target.value)
      if (e.target.value === '') return
      if (e.keyCode === 13) {
        this.props.onReceiveKeywords(this.state.value)
        this.setState({
          value: ''
        })
      }
    }
  }
  

  render() {
    return (
      <div>
        <input type="text" value={this.state.value} onChange={this.handleChange()}
          onKeyUp={this.handleKeyUp()}
        />
      </div>
    )
  }
}
